import 'package:flutter_app/tools/http.dart';
import 'package:isolate/isolate.dart';
import 'package:shared_preferences/shared_preferences.dart';

class Global {
  static String userName = "";
  static String userEmail = "";
  static String userId = "";
  static String imageUrlPath =
      "https://xinkong.obs.cn-east-3.myhuaweicloud.com/image/";
  // static String serversUrl = "http://192.168.1.158:8080";
  static String serversUrl = "http://zabxx.club";

  static Future<LoadBalancer> loadBalancer;

  //初始化全局信息，会在APP启动时执行
  static Future init() async {
    final prefs = await SharedPreferences.getInstance();
//初始化线程池
    loadBalancer = LoadBalancer.create(4, IsolateRunner.spawn);

    // prefs.clear();
// Try reading data from the counter key. If it does not exist, return 0.
    userId = prefs.getString("userId") ?? "";
    if (userId.length == 0) {
      userId = await m_http.getUserId();
      prefs.setString("userId", userId);
    }

    userName = prefs.getString("userName") ?? "";
    userEmail = prefs.getString("userEmail") ?? "";
  }

  static editUserInfo(newUserName, newUserEmail) async {
    userName = newUserName;
    userEmail = newUserEmail;
    final prefs = await SharedPreferences.getInstance();
    prefs.setString("userName", userName);
    prefs.setString("userEmail", userEmail);
  }
  // 持久化Profile信息

}
